efform_onload = function ()
{

	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCN31","query");
	var _info = new EiInfo();
	
	efgrid_onRowClicked("ef_grid_r",0);
	$('#ef_region_detail').hide();
	$('#inqu_status-0-fdBjdw').val($('#fdBjdw').val());
	$('#inqu_status-0-fdForeignId').val($('#fdForeignId').val());
	
	

}; 
var ajax_callback1 = {
	onSuccess : function(eiInfo) {
		efwindow.hide(); 
		var grid = efgrid.getGridObject("ef_grid_d");
		grid.refresh(eiInfo);
	},
	onFail : function(eMsg) {}
};
button_query_onclick = function () 
{   	
	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCN31","query");
}
button_update_onclick = function (){ 
	if (isSelected("ef_grid_r") == 0)return; 
//	efgrid.submitForm( "ef_grid_r", "ZM","ZMCN31","update",true);
	//以下为行增有重复性校验
	var info = getSCZXEiInfos("ZMCN31","ef_grid_r");
	if (null != info) {
		//先校验是否允许修改：如果明细有记录生效，不能修改主表
		EiCommunicator.send("ZMCN31", "validate1", info, validate1_callback);
	}
}
button_insert_onclick = function (){
	if (isSelected("ef_grid_r") == 0)return; 
//	efgrid.submitForm( "ef_grid_r", "ZM","ZMCN31","insert",true);
	//以下为行增有重复性校验
	var info = getSCZXEiInfos("ZMCN31","ef_grid_r");
	if (null != info) { 
		//进行重复性校验
		EiCommunicator.send("ZMCN31", "validate", info, validate_callback);
	}
} 
button_delete_onclick = function (){
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		//先校验是否允许删除：如果明细有记录，不能删除主表
		if(r){
			//efgrid.submitForm( "ef_grid_r", "ZM","ZMCN31","delete",true);
			var info = getSCZXEiInfos("ZMCN31","ef_grid_r");
			if (null != info) { 
				EiCommunicator.send("ZMCN31", "validate1", info, validate1_callback);
			}
		}
	}); 
}

var fdBjdw,fdForeignId;
efgrid_onRowClicked = function( grid_id, row_index ){
	if(grid_id == "ef_grid_r"){ 
		$('#ef_region_detail').show();
		var grid = efgrid.getGridObject(grid_id);
		
		fdBjdw=grid.getCellValueByColumnName(row_index,"fdBjdw");
		fdForeignId=grid.getCellValueByColumnName(row_index,"fdKeyId");
		//隐藏/显示从表按钮 
		var info = new EiInfo();
		
		info.set("fdBjdw",fdBjdw); 
		info.set("fdForeignId",fdForeignId); 
		
		$('#fdBjdw').val(fdBjdw);
//		$('#fdForeignId').val(fdForeignId);
	//	$('#inqu_status-0-fdBjdw').val(fdBjdw);
		$('#inqu_status-0-fdForeignId').val(fdForeignId);
		EiCommunicator.send("ZMCN33", "query", info, ajax_callback);  
	}
	if(grid_id == "ef_grid_d"){ 
		var grid = efgrid.getGridObject(grid_id); 
		var selectedRow=grid.getRowData(row_index);
		for(var item in selectedRow){
			var colname=item;
			var colvalue=selectedRow[item];
			$('#ef_region_inqu1').find('#inqu_status1-0-'+colname).val(colvalue);
		} 
	}
	
}
var ajax_callback= {
	onSuccess: function(eiInfo) { 
		 efwindow.hide();
		 var grid = efgrid.getGridObject("ef_grid_d");
		 grid.refresh(eiInfo);
	},
	onFail:function(eMsg)
	{
		EFAlert("新增失败，原因："+eMsg); 
	}
}
/*var validate_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
					efwindow.hide();
					var grid = efgrid.getGridObject("ef_grid_r");
					grid.refresh(eiInfo);
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}*/
var validate1_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
		/*				 efwindow.hide();
				 var grid = efgrid.getGridObject("ef_grid_r");
				 grid.refresh(eiInfo);*/
				var oper="delete";
				if(eiInfo.get("efCurButtonEname")=="UPDATE"){
					//进行重复性校验
					oper="update";
					EiCommunicator.send("ZMCN31", "validate", eiInfo, validate_callback);
				}else{
					efgrid.submitForm( "ef_grid_r", "ZM","ZMCN31","delete",true);
				}
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
	}
var validate_callback={
	onSuccess:function(eiInfo){
		if(eiInfo.getStatus()==-1){
			EFAlert("操作失败，原因："+eiInfo.getMsg());
		}else{
	/*				 efwindow.hide();
			 var grid = efgrid.getGridObject("ef_grid_r");
			 grid.refresh(eiInfo);*/
			var oper="insert";
			if(eiInfo.get("efCurButtonEname")=="UPDATE"){
				oper="update";
			}
			efgrid.submitForm("ef_grid_r", "ZM", "ZMCN31",oper, true);
		}
	},
	onFail:function(eMsg)
	{
		EFAlert("操作失败，原因："+eMsg); 
	}
}
var validate_detail_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
/*				 efwindow.hide();
				 var grid = efgrid.getGridObject("ef_grid_d");
				 grid.refresh(eiInfo);*/
				var oper="insert";
				if(eiInfo.get("efCurButtonEname")=="UPDATE"||eiInfo.get("efCurButtonEname")=="UPDATE1"){
					oper="update";
				}
				efgrid.submitForm("ef_grid_d", "ZM", "ZMCN33",oper, true);
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}


button_insert1_onclick = function (){
		//以下方式为行增
		if (isSelected("ef_grid_d") == 0)return; 
		//以下为行增有重复性校验
		var info = getSCZXEiInfos("ZMCN31","ef_grid_d");
		if (null != info) { 
			EiCommunicator.send("ZMCN33", "validate", info, validate_detail_callback);
		}
	}
	button_update1_onclick = function (){ 
		var grid=isSelected("ef_grid_d");
		if (grid == 0)return; 
		var rows=grid.getCheckedRows();
		for(var i=0;i<rows.length;i++)
		{
			if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
			{
				EFAlert("只能对草拟的记录进行修改！"); return;
			}
		}
		if (isSelected("ef_grid_d") == 0)return; 
		var info = getSCZXEiInfos("ZMCN31","ef_grid_d");
		if (null != info) { 
			EiCommunicator.send("ZMCN33", "validate", info, validate_detail_callback);
		}
		
	}
	button_delete1_onclick = function (){
		var grid=isSelected("ef_grid_d");
		if (grid == 0)return; 
		var rows=grid.getCheckedRows();
		for(var i=0;i<rows.length;i++)
		{
			if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
			{
				EFAlert("只能对草拟的记录进行删除！"); return;
			}
		}
		EFConfirm('你确认要删除吗?', '确认框', function(r) {
			if(r)efgrid.submitForm( "ef_grid_d", "ZM","ZMCN33","delete",true);
		}); 
	}
		

	button_report_onclick = function (){
		var grid=isSelected("ef_grid_d");
		if (grid == 0)return; 
		var rows=grid.getCheckedRows();
		for(var i=0;i<rows.length;i++)
		{
			if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
			{
				EFAlert("该记录已经上报了！"); return;
			}
		}
		EFConfirm('你确认要上报吗?', '确认框', function(r) {
			if(r)efgrid.submitForm( "ef_grid_d", "ZM","ZMCN33","report",true);
		}); 
	}

	
	efgrid_afterAddNewRow = function(grid_id){ 
		var grid = efgrid.getGridObject(grid_id);
		var rows = grid.getCheckedRows();  
		if(grid_id=="ef_grid_d")
		{

		   
			for(var i = 0 ; i < rows.length;i++){
				grid.setCellValue(rows[i],0,"草拟",TYPE_DATA);
	//			grid.setCellValue(rows[i],3,fdBjdw,TYPE_DATA);
			}
		}
	}
